#include "game.h"

int chess(char a[HAN][LIE], int han, int lie)
{
	int x = 0;
	int y = 0;
	for (x = 0; x <han; x++)
	{
		for (y = 0; y < lie; y++)
		{
			a[x][y]=' ';
		}
	}
}

int my_print(char a[HAN][LIE], int han, int lie)
{
	int x = 0;
	for (x = 0; x < han; x++)
	{
		printf(" %c | %c | %c \n", a[x][0], a[x][1],a[x][2]);
		if(x<han-1)
		{
			printf("---|---|---\n");
		}
	}
}

int player(char a[HAN][LIE], int han, int lie)
{
	int x = 0;
	int y = 0;
	printf("玩家走：");
	//判断坐标合法性
	while (1)
	{
		scanf("%d%d", &x, &y);
		if (x >= 1 && x <= han && y >= 1 && y <= lie)
		{
			if (a[x - 1][y - 1] == ' ')
			{
				a[x - 1][y - 1] = '#';
				system("cls");
				my_print(a, HAN, LIE);
				break;
			}
			else
				printf("坐标被占用,请重新输入");
		}
		else
		{
			printf("坐标非法，请重新输入");
		}
	}
}

int com(char a[HAN][LIE], int han, int lie)
{
	while (1)
	{
		int x = rand() % han;
		int y = rand() % lie;
		if (a[x][y] == ' ')
		{
			a[x][y] = '&';
			system("cls");
			my_print(a, HAN, LIE);
			break;
		}
	}
}

int judje(char a[HAN][LIE], int han, int lie)
{
	int i = 0;
	int j = 0;
	for (i = 0; i < HAN; i++)
	{
		if (a[i][0] == a[i][1] && a[i][2] == a[i][1] && a[i][1] != ' ')
			return a[i][0];
	}
	for (j = 0; j < LIE; j++)
	{
		if (a[0][j] == a[1][j] && a[1][j] == a[2][j] && a[0][j] != ' ')
			return a[0][j];
	}
	if (a[0][0] == a[1][1] && a[2][2] == a[1][1] && a[2][2] != ' ')
	{
		return a[0][0];
	}
	if (a[0][2] == a[1][1] && a[2][0] == a[1][1] && a[2][0] != ' ')
	{
		return a[0][2];
	}
	for (i = 0; i < han; i++)
	{
		for (j = 0; j < lie; j++)
		{
			if (a[i][j] == ' ')
				return 'C';//棋盘没满
		}
	}
	return 'Q';//棋盘满了
}

